# C++ code in the runtime and standard library should generally avoid
# introducing static constructors or destructors.
set(SWIFT_CORE_CXX_FLAGS)

if(CMAKE_SYSTEM_NAME STREQUAL "CYGWIN")
  list(APPEND SWIFT_CORE_CXX_FLAGS "-mcmodel=large")
endif()

check_cxx_compiler_flag("-Werror -Wglobal-constructors" CXX_SUPPORTS_GLOBAL_CONSTRUCTORS_WARNING)
if(CXX_SUPPORTS_GLOBAL_CONSTRUCTORS_WARNING)
  list(APPEND SWIFT_CORE_CXX_FLAGS "-Wglobal-constructors")
endif()

check_cxx_compiler_flag("-Wexit-time-destructors" CXX_SUPPORTS_EXIT_TIME_DESTRUCTORS_WARNING)
if(CXX_SUPPORTS_EXIT_TIME_DESTRUCTORS_WARNING)
  list(APPEND SWIFT_CORE_CXX_FLAGS "-Wexit-time-destructors")
endif()

# We don't want runtime C++ code to export symbols we didn't explicitly
# choose to.
check_cxx_compiler_flag("-fvisibility=hidden" CXX_SUPPORTS_DEFAULT_HIDDEN_VISIBILITY)
if(CXX_SUPPORTS_DEFAULT_HIDDEN_VISIBILITY)
  list(APPEND SWIFT_CORE_CXX_FLAGS "-fvisibility=hidden")
endif()

if(SWIFT_BUILD_STDLIB)
  # These must be kept in dependency order so that any referenced targets
  # exist at the time we look for them in add_swift_*.
  add_subdirectory(SwiftShims)
  add_subdirectory(runtime)
  add_subdirectory(stubs)
  add_subdirectory(core)
  add_subdirectory(SwiftOnoneSupport)
  add_subdirectory(Reflection)
  add_subdirectory(SwiftRemoteMirror)
endif()

if(SWIFT_BUILD_SDK_OVERLAY)
  add_subdirectory(Platform)
endif()

if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
  if(SWIFT_BUILD_SDK_OVERLAY)
    add_subdirectory(SDK)
  endif()
endif()
